﻿using System;
using System.Collections;
using System.Collections.Generic;

using AUV5.Model;
using AUV5.DAL.Interface;

namespace AUV5.DAL.Dao
{
    /// <summary>
    /// 功能：     Message业务接口的实现
    /// 作者：     lwl
    /// 日期：     2011/10/14
    /// 修改日期： 
    /// 修改人：
    /// 修改内容：
    /// </summary>
    public class MessageSqlMapDao : BaseSqlMapDao, IMessageDao
    {
        private static MessageSqlMapDao instance = null;
        private static object syncRoot = new object();

        private MessageSqlMapDao()
        {
            //
            // TODO: 此处添加MessageSqlMapDao的构造函数
            //
        }
        public static IMessageDao Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new MessageSqlMapDao();
                        }
                    }
                }
                return instance;
            }
        }

        /// <summary>
        /// 得到最大行数
        /// </summary>
        /// <returns></returns>
        public int GetMaxCounts()
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectMessageByMaxCounts", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.IList<Message> GetList()
        {
            try
            {
                return ExecuteQueryForList<Message>("SelectMessage", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public System.Collections.Generic.IList<Message> GetListByParameters(object objParameters)
        {
            try
            {
                return ExecuteQueryForList<Message>("SelectMessageByParameters", objParameters);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到明细
        /// </summary>
        /// <param name="MessageID"></param>
        /// <returns></returns>
        public Message GetDetail(System.String messageid)
        {
            try
            {
                Message mes= ExecuteQueryForObject<Message>("SelectMessage", messageid) as Message;

                Handler.MessageHandler handler=new Handler.MessageHandler();
                return handler.GetFullMessage(mes);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public object Add(Message message)
        {
            //int id = GetId("Message");
            //message.MessageID = id;

            try
            {
                return ExecuteInsert("InsertMessage", message);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public int Update(Message message)
        {
            try
            {
                return ExecuteUpdate("UpdateMessage", message);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="MessageID"></param>
        /// <returns></returns>
        public int Delete(System.String messageid)
        {
            try
            {
                return ExecuteDelete("DeleteMessage", messageid);
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public int Delete(Message message)
        {
            try
            {
                return ExecuteDelete("DeleteMessage", message.MessageID);
            }
            catch
            {
                throw;
            }
        }


        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <param name="pager"></param>
        /// <returns></returns>
        public IList<Message> GetPagedList(NetPager pager)
        {
            try
            {
                Handler.MessageHandler handler = new Handler.MessageHandler();
                ExecuteWithRowDelegate("GetPagedMessage", pager, new IBatisNet.DataMapper.RowDelegate(handler.GetFullList));
                return handler.messagelist;
                //return ExecuteQueryForList<Message>("GetPagedMessage", pager);
            }
            catch
            {
                
                throw;
            }
        }


        /// <summary>
        /// 批量更新
        /// </summary>
        /// <param name="list"></param>
        public void UpdateList(Hashtable ht)
        {
            try
            {
               ExecuteUpdate("UpdateMessageByList", ht);
            }
            catch 
            {
                
                throw;
            }
        }
    }
}
